//
//  ServiceManager.m
//  aloqa
//
//  Created by mkoo sun on 12-8-23.
//  Copyright (c) 2012Âπ?exodus. All rights reserved.
//

#import "ServiceManager.h"
#import "AroundServiceHost.h"
#import "SessionServiceHost.h"
#import "ReminderServiceHost.h"

ServiceManager* serviceManagerInstance = NULL;

@implementation ServiceManager

@synthesize debug;
@synthesize releaseName;
@synthesize deviceId;
@synthesize softVer;
@synthesize iosVer;

//-------------------------------------------------------------------------------------------
+(ServiceManager*) getInstance
{
    if(serviceManagerInstance == NULL)
    {
        serviceManagerInstance = [[ServiceManager alloc]init];
    }
    return serviceManagerInstance;
}

//-------------------------------------------------------------------------------------------
- (id)init
{
    self = [super init];
    if (self)
    {
        simpleStorageService = [[SimpleStorageService alloc]init];
        eventService = [[EventService alloc]init];
        httpService = [[HttpService alloc]init];
        sessionService = [[SessionService alloc]init];
        
        debug = NO;
        releaseName = @"";
        deviceId = @"";
        softVer = @"";
        iosVer = @"5.0";
    }
    return self;
}

- (void)dealloc
{
    [storageService release];
    [eventService release];
    [httpService release];
    [sessionService release];
    
    [super dealloc];
}

//-------------------------------------------------------------------------------------------
-(id) getService:(enum ServiceType) type
{
    if(type == AROUND_SERVICE)
    {
        return aroundService;
    }
    else if(type == SIMPLESTORAGE_SERVICE)
    {
        return simpleStorageService;
    }
    //    else if(type == TRANSACTION_SERVICE)
    //    {
    //    }
    else if(type == EVENT_SERVICE)
    {
        return eventService;
    }
    //    else if(type == TIMER_SERVICE)
    //    {
    //    }
    else if(type == COMPONENT_SERVICE)
    {
        return componentService;
    }
    else if(type == HTTP_SERVICE)
    {
        return httpService;
    }
    else if(type == LOG_SERVICE)
    {
        return logService;
    }
    else if(type == SESSION_SERVICE)
    {
        return sessionService;
    }
    else if(type == REMINDER_SERVICE)
    {
        return reminderService;
    }
    else if(type == SCHEDULE_SERVICE)
    {
        return scheduleService;
    }
    else if(type ==MYWEIBO_SERVICE)
    {
        return myweiboService;
    }
    
    return Nil;
}

//-------------------------------------------------------------------------------------------
+ (void) onCreate
{
    [ServiceManager getInstance];
    [[AroundServiceHost getInstance] onCreate];
    [[SessionServiceHost getInstance] onCreate];
    [[ReminderServiceHost getInstance] onCreate];
}

//-------------------------------------------------------------------------------------------
+ (void) onDestroy
{
    [[AroundServiceHost getInstance] onDestroy];
    [[SessionServiceHost getInstance] onDestroy];
    [[ReminderServiceHost getInstance] onDestroy];
}

@end
